<template>
  <div class='container'>
    <el-dialog title="题目预览" :visible="previewDialogVisibleShow" width="50%" @close="close">
      <el-row>
        <el-col class="box-margin">
          <el-row>
            <el-col :span="6"><span>【题型】：</span>
              <span v-if="previewList.questionType === '1'">单选题</span>
              <span v-else-if="previewList.questionType === '2'">多选题</span>
              <span v-else-if="previewList.questionType === '3'">简答题</span>
            </el-col>
            <el-col :span="6"><span>【编号】：</span><span>
                {{ previewList.id }}
              </span></el-col>
            <el-col :span="6"><span>【难度】：</span>
              <span v-if="previewList.difficulty === '1'">简单</span>
              <span v-else-if="previewList.difficulty === '2'">一般</span>
              <span v-else-if="previewList.difficulty === '3'">困难</span>

            </el-col>
            <el-col :span="6"><span>【标签】：</span><span>
                {{ previewList.tags }}
              </span></el-col>
          </el-row>
        </el-col>
        <el-col class="box-margin">
          <el-row>
            <el-col :span="6"><span>【学科】：</span><span>
                {{ previewList.subjectName }}
              </span></el-col>
            <el-col :span="6"><span>【目录】：</span><span>
                {{ previewList.directoryName }}
              </span></el-col>
            <el-col :span="6"><span>【方向】：</span><span>
                {{ previewList.direction }}</span></el-col>
          </el-row>
        </el-col>
      </el-row>
      <hr />

      <!-- 题干 -->
      <el-row>
        【题干】：
        <div>
          <p v-html="previewList.question" style="color:blue;"></p>
        </div>
        <div v-if="previewList.questionType === '1'">
          <p>单选题 选项：（以下选中的选项为正确答案）</p>
          <div class="box-margin" v-for="item in previewList.options" :key="item.id">
            <el-radio @change="radioChange" v-model="checkedRadio" :label="item.isRight">{{ item.title }}</el-radio>
          </div>
        </div>
        <div v-else-if="previewList.questionType === '2'">
          <p>多选题 选项：（以下选中的选项为正确答案）</p>
          <el-checkbox-group v-model="checkedCheckbox">
            <div class="box-margin" v-for="item in previewList.options" :key="item.id">
              <el-checkbox @change="chechboxChange" :label="item.isRight">{{ item.title }}</el-checkbox>
            </div>
          </el-checkbox-group>
        </div>
      </el-row>
      <hr />
      <el-row>
        【参考答案】：
        <el-button type="danger" size="small" @click="videoPlay">视频答案预览</el-button>
        <div v-show="videoShow">
          <video ref="playerRef" width="400px" :src="previewList.videoURL" controls></video>
        </div>
      </el-row>
      <hr />
      <el-row class="box-margin">
        <el-col :span="4">
          <p>【答案解析】：</p>
        </el-col>
        <el-col :span="20"><span v-html="previewList.answer"></span></el-col>
      </el-row>
      <hr />
      <el-row class="box-margin">
        <el-col :span="4"><span>【题目备注】：</span></el-col>
        <el-col :span="20">{{ previewList.remarks }}</el-col>
      </el-row>
      <!--  -->
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="close">关 闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/questions'
export default {
  name: 'PreviewIndex',
  props: {
    previewDialogVisibleShow: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      checked: true,
      previewList: {},
      checkedRadio: 1,
      checkedCheckbox: [1],
      videoShow: false
    }
  },
  methods: {
    // 关闭弹层
    close () {
      this.$refs.playerRef.pause()
      this.videoShow = false
      this.previewList = {}
      this.$emit('update:previewDialogVisibleShow', false)
    },
    // 加载预览列表
    async loadingPreviewList (id) {
      const { data } = await detail({ id })
      // console.log(data)
      this.previewList = data
    },
    // 单选框不能改变
    radioChange () {
      this.checkedRadio = 1
    },
    // 复选框不能改变
    chechboxChange () {
      this.checkedCheckbox = [1]
    },
    // 视频播放
    videoPlay () {
      if (!this.previewList.videoURL) {
        return
      }
      this.$refs.playerRef.play()
      this.videoShow = true
    }
  }
}
</script>

<style scoped lang='less'>
.box-margin {
  margin: 10px 0;
}
/deep/.el-dialog__footer {
  text-align: right;
}
</style>
